package com.lyy.java_chatroom.model;

import com.lyy.java_chatroom.constant.Constant;
import lombok.Data;

@Data
public class Result {
    private int code;
    private String errmsg;
    private Object data;

    //业务成功时返回方法
    public static Result success(Object data){
        Result result=new Result();
        result.setCode(Constant.RESULT_CODE_SUCCESS);//200
        result.setErrmsg("");
        result.setData(data);
        return result;
    }

    //业务失败时返回方法
    public static Result fail(String msg){//(-1,msg)
        Result result=new Result();
        result.setCode(Constant.RESULT_CODE_FALT);
        result.setErrmsg(msg);
        return result;
    }

    //用户未登录时返回方法
    public static Result unlogin(){
        Result result=new Result();
        result.setCode(Constant.RESULT_CODE_UNLOGIN);//-2
        result.setErrmsg("用户未登录");
        return result;
    }
}
